import $get from 'lodash/get'

/**
 * 区分正式环境和测试环境返回http请求对应参数
 *
 * @returns <Object>
 */

function checkTestIp () {
	let ipType = $get(process, 'env.IP_TYPE', '')
	return ipType.indexOf('test14') > -1
}

export const isTestIp = checkTestIp()

function getHttpConfig () {
	const publicIP = $get(this, 'ctx.APP_CONFIG.publicIP', '')
	const cookie = $get(this, 'ctx.request.header.cookie', '')
	const url = $get(this, 'ctx.url', '')
	let enableTest = /test=on/.test(url) || (cookie.indexOf('debug_test') > -1 && (
		publicIP.indexOf('test') > -1 ||
		process.env.NODE_ENV === 'development'
	))
	const config = {
		domain: 'h5access.yangshipin.cn',
		l5modid: '65',
		l5cmd: '5963776'
	}
	if (isTestIp || enableTest) {
		config.domain = 'h5api.yangshipin.cn'
		config.l5cmd = '9371648'
	}
	return config
}

export default getHttpConfig
